<template>
    <div style="width:100%;height:100%;" id="visite_volume_con"></div>
</template>

<script>
import echarts from 'echarts';

import util from '@/libs/util';
import Cookies from 'js-cookie';
import getDate from '@/util/getDate.js';

export default {
    name: 'visiteVolume',
    data () {
        return {
            baseuser: JSON.parse(Cookies.get('baseUser'))
        };
    },
    mounted () {
        this.$nextTick(() => {
            let visiteVolume = echarts.init(document.getElementById('visite_volume_con'));
            let xAxisData = [];
            let data1 = [];
            let data2 = [];
            for (let i = 0; i < 20; i++) {
                xAxisData.push('类目' + i);
                data1.push((Math.sin(i / 5) * (i / 5 - 10) + i / 6) * 5);
                data2.push((Math.cos(i / 5) * (i / 5 - 10) + i / 6) * 5);
            }
            util.ajax.post('/busine/prizedownloadcount/findAll', util.toFormData({
                orgid: (this.baseuser.type === 2 ? this.baseuser.orgId : '')
            })).then(res => {
                let yAxisData = [];
                let seriesData = [];
                let countList = res.data.data;
                countList.forEach((item) => {
                    yAxisData.push(getDate.getDate(item.downloaddate, 'date'));
                    seriesData.push({
                        value: item.count,
                        name: getDate.getDate(item.downloaddate, 'date'),
                        itemStyle: {normal: {color: '#2d8cf0'}}
                    });
                })
                const option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    grid: {
                        top: 0,
                        left: '2%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                    },
                    yAxis: {
                        type: 'category',
                        data: yAxisData,
                        nameTextStyle: {
                            color: '#c3c3c3'
                        }
                    },
                    series: [
                        {
                            name: '下载量',
                            type: 'bar',
                            data: seriesData
                        }
                    ]
                };

                visiteVolume.setOption(option);

                window.addEventListener('resize', function () {
                    visiteVolume.resize();
                });
            });
        })
    }
}
</script>
